import { SALE_ORDER_TYPE } from '@/model/type'

export const columns = ctx => {
  return [
    {
      prop: 'returnedNo',
      headCheck: '1',
      label: '回款编号',
      minWidth: 120
    },
    {
      prop: 'returnedTypeName',
      headCheck: '1',
      label: '回款类型'
    },
    {
      prop: 'saleOrderNo',
      label: '关联销售单',
      headCheck: '1',
      hide: ctx.searchForm.checkStatus !== '3',
      render: (h, row) => {
        return [
          <el-button
            type="text"
            onClick={() => {
              ctx.onExtendShow(row.saleId, 'sale')
            }}
          >
            {row.saleOrderNo}
          </el-button>
        ]
      }
    },
    {
      label: '销售单类型',
      headCheck: '1',
      minWidth: 120,
      render: (h, row) => {
        return [
          <el-tag size="medium" type={SALE_ORDER_TYPE[row.typeName] || 'primary'}>
            {row.typeName || '-'}
          </el-tag>
        ]
      }
    },
    {
      prop: 'customerName',
      label: '关联客户',
      headCheck: '1',
      hide: ctx.searchForm.checkStatus !== '3',
      render: (h, row) => {
        return [
          <el-button
            type="text"
            onClick={() => {
              ctx.onExtendShow(row.customerId, 'customer')
            }}
          >
            {row.customerName}
          </el-button>
        ]
      }
    },
    {
      prop: 'returnedPeriods',
      label: '回款期次',
      headCheck: '1',
      hide: ctx.searchForm.checkStatus !== '3',
      render: (h, row) => {
        return [<span>第{row.returnedPeriods}期</span>]
      }
    },
    {
      prop: 'createTime',
      headCheck: '1',
      label: '创建时间',
      hide: ctx.searchForm.checkStatus !== '3'
    },
    {
      prop: 'returnedTime',
      headCheck: '1',
      label: '回款日期',
      hide: ctx.searchForm.checkStatus !== '3'
    },
    {
      // prop: 'returnedMoney',
      headCheck: '1',
      label: '回款金额(元)',
      hide: ctx.searchForm.checkStatus !== '3',
      render: (h, row) => {
        return (
          <span class={row.returnedType.toString() !== '1' ? 'fc-error' : ''}>{row.returnedMoney}</span>
        )
      }
    },
    // 回款列表新增【本期回款提成】
    {
      prop: 'returnedPrice',
      headCheck: '1',
      label: '本期回款提成',
      hide: ctx.searchForm.checkStatus !== '3'
    },
    // {
    //   prop: 'balanceAmount',
    //   headCheck: '1',
    //   label: '红冲金额(元)',
    //   hide: ctx.searchForm.checkStatus !== '3'
    // },
    {
      prop: 'overdueStatus',
      headCheck: '1',
      label: '逾期状态',
      hide: ctx.searchForm.checkStatus !== '3',
      render: (h, row) => {
        const style =
          row.overdueStatus === '1'
            ? 'success'
            : row.overdueStatus === '2'
              ? 'danger'
              : ''
        return <el-tag size="medium" type={style}>{row.overdueStatusName}</el-tag>
      }
      // render: (h, row) => {
      //   const style =
      //     row.overdueStatus === '1'
      //       ? 'el-button--success plr10 ptb5 bd-r8 fs14'
      //       : row.overdueStatus === '2'
      //         ? 'el-button--danger plr10 ptb5 bd-r8 fs14'
      //         : ''
      //   return <el-button plain class={style}>{row.overdueStatusName}</el-button>
      // }
    },
    {
      prop: 'operator',
      headCheck: '1',
      label: '操作人',
      hide: ctx.searchForm.checkStatus === '3'
    },
    {
      prop: 'updateTime',
      headCheck: '1',
      label: '修改时间',
      hide: ctx.searchForm.checkStatus === '3'
    },
    {
      button: true,
      label: '操作',
      headFixed: '1',
      fixed: 'right',
      width: 240,
      render: (h, row) => {
        const detail = (
          <el-button
            type="text"
            onClick={() => {
              ctx.onDetail(row)
            }}
          >
            详情
          </el-button>
        )
        const edit = (
          <el-button
            type="text"
            onClick={() => {
              ctx.onEdit(row)
            }}
          >
            编辑
          </el-button>
        )
        const del = (
          <el-button
            type="text"
            onClick={() => {
              ctx.onDel(row)
            }}
          >
            删除
          </el-button>
        )
        const approval = (
          <el-button
            type="text"
            onClick={() => {
              ctx.onApproval(row)
            }}
          >
            提交审批
          </el-button>
        )
        const revoke = (
          <el-button
            type="text"
            onClick={() => {
              ctx.onRevoke(row)
            }}
          >
            撤销审批
          </el-button>
        )
        // 审批状态
        /**
         * name: "未提交", value: "0"
         * name: "待审核", value: "1"
         * name: "已拒绝", value: "2"
         * name: "已通过", value: "3"
         * name: "已退回", value: "4"
         */
        return ctx.searchForm.checkStatus === '3'
          ? [detail]
          : ctx.searchForm.checkStatus === '0' ||
            ctx.searchForm.checkStatus === '2' ||
            ctx.searchForm.checkStatus === '4'
            ? [edit, detail, del, approval]
            : ctx.searchForm.checkStatus === '1'
              ? [detail, revoke]
              : []
      }
    }
  ]
}

// 订单状态
export const orderStatusList = [
  {
    name: '部分退款',
    value: '1'
  },

  {
    name: '全部退款',
    value: '2'
  },
  {
    name: '成功订单',
    value: '3'
  }
]

// 回款类型下拉
export const returnedTypeSelect = [
  {
    name: '正常回款',
    value: '1'
  },

  {
    name: '退款红冲',
    value: '2'
  }
]

export const timeTypeList = [
  {
    value: '1',
    name: '回款日期'
  },
  {
    value: '2',
    name: '创建时间'
  }
]
